package cn.jdy.platform.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.platform.entity.FriendLink;

/**
 * 友情链接
 *
 * @author: zhaigt
 * @date: 2014-3-17 16:53
 */
@Service
public class FriendLinkService extends BaseDao<FriendLink> {

  /**
   * 拼装条件
   * @param friendLink
   * @return
   */
  private DetachedCriteria createFilter(FriendLink friendLink) {
    DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
    if(!StringUtil.isNullOrEmpty(friendLink.getId())){
      dc.add(Restrictions.eq("id", friendLink.getId()));
    }
    if(!StringUtil.isNullOrEmpty(friendLink.getStatus())){
      dc.add(Restrictions.eq("status", friendLink.getStatus()));
    }
    if(!StringUtil.isNullOrEmpty(friendLink.getType())){
      dc.add(Restrictions.eq("type", friendLink.getType()));
    }
    return dc;
  }

	/**
	 * @param friendLinkType
	 * @return 友情链接列表
	 * @description: 查询友情链接列表
	 */
	public List<FriendLink> query(FriendLink friendLink) {
	  if(friendLink == null) return super.findAll();
	  if(friendLink.getiDisplayLength() > 0){
	    return super.find(createFilter(friendLink),friendLink.getiDisplayStart(), friendLink.getiDisplayLength());
	  }
	  return super.find(createFilter(friendLink));
	}
	
	/**
	 * 按条件查询记录
	 * @param friendLink
	 * @return
	 */
	public Long count(FriendLink friendLink){
    return super.count(createFilter(friendLink));
  }

}